﻿IF EXISTS
(
    SELECT TOP (1)
           1
    FROM sysobjects
    WHERE id = OBJECT_ID(N'tr_CF_Student_All')
          AND OBJECTPROPERTY(OBJECT_ID('tr_CF_Student_All'), N'IsTrigger') = 1
)
BEGIN
    DROP TRIGGER tr_CF_Student_All;
END;
GO

CREATE TRIGGER tr_CF_Student_All
ON dbo.CF_Student
AFTER UPDATE, DELETE, INSERT
AS
BEGIN
    DECLARE @IsInsert BIT,
            @IsUpdate BIT,
            @IsDelete BIT;
    IF EXISTS (SELECT 1 FROM inserted) AND NOT EXISTS (SELECT 1 FROM deleted)
        SET @IsInsert = 1;
    ELSE
        SET @IsInsert = 0;

    IF EXISTS (SELECT 1 FROM inserted) AND EXISTS (SELECT 1 FROM deleted)
        SET @IsUpdate = 1;
    ELSE
        SET @IsUpdate = 0;

    IF NOT EXISTS (SELECT 1 FROM inserted) AND EXISTS (SELECT 1 FROM deleted)
        SET @IsDelete = 1;
    ELSE
        SET @IsDelete = 0;

    DECLARE @UserIntID AS BIGINT;

	IF (@IsInsert = 1)
    BEGIN
        -- 新增
		PRINT('新增')
    END;
    IF (@IsUpdate = 1)
    BEGIN
		--更新
		PRINT('更新')
    END;
   
    IF (@IsDelete = 1)
    BEGIN
        -- 删除
		PRINT('删除')

    END;

END;
